package ppz.android.com.ttttxxxx.accesslibility.service;
import android.accessibilityservice.AccessibilityService;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.view.accessibility.AccessibilityEvent;

import ppz.android.com.ttttxxxx.ReceivedHongBaoEvent;
import ppz.android.com.ttttxxxx.accesslibility.AccessibilityHelper;
import ppz.android.com.ttttxxxx.accesslibility.config.WXIDManage;
import ppz.android.com.ttttxxxx.accesslibility.config.WXPageUIManage;


@RequiresApi(api = Build.VERSION_CODES.DONUT)
public  class WXAccesslibilityService extends AccessibilityService {
    private  boolean isSendHongBaoPageUI=false;
    private  String  currentFriend="";
    @Override
    protected void onServiceConnected() {
        super.onServiceConnected();
    }
    @Override
    public void onCreate() {
        super.onCreate();
    }

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        switch (event.getEventType()){
            case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED:

                break;
            case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
                break;
        }
    }
    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    private  void  onPageChange(String className){
        isSendHongBaoPageUI=false;
        if(WXPageUIManage.isSendHongBaoPageUI(className)){
            isSendHongBaoPageUI=true;
            return;
        }
        if(WXPageUIManage.isLuckyMoneyDetailUI(className)){
            writeReceivedHongBaoHistory();
            return;
        }
        if(WXPageUIManage.isChatRoomUI(className)){
            currentFriend=AccessibilityHelper.findNodeInfosById(getRootInActiveWindow(),WXIDManage.getFriendTextViewId()).getText().toString();
            return;
        }
    }
    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    private  void writeReceivedHongBaoHistory(){
        ReceivedHongBaoEvent event=new ReceivedHongBaoEvent();
        event.setFriendName(AccessibilityHelper.findNodeInfosById(getRootInActiveWindow(), WXIDManage.getHongBaoFriendId()).getText().toString());
        event.setMoney(AccessibilityHelper.findNodeInfosById(getRootInActiveWindow(),WXIDManage.getHongBaoMoneyId()).getText().toString());
    }

    @Override
    public void onInterrupt() {

    }


}
